
/*--------------------------------------------------------------------------

When a unit passes through a specific terrain,
if the terrain has a sound effect set, that sound effect will be played.

Usage:
Describe

{soundId: 0}

etc. at a custom parameter of the terrain.
Replace 0 with the ID of the original sound effect.

Author:
SapphireSoft
https://srpgstudio.com/

History:
2023/09/26 Released

--------------------------------------------------------------------------*/

(function() {

var alias1 = SimulateMove._playMovingSound;
SimulateMove._playMovingSound = function() {
if (this._moveCount % 2 === 0) {
Miscellaneous.playFootstepEx(this._unit, Math.floor(this._xPixel / GraphicsFormat.MAPCHIP_WIDTH), Math.floor(this._yPixel / GraphicsFormat.MAPCHIP_HEIGHT));
}
};

Miscellaneous.playFootstepEx = function(unit, x, y) {
var handle;
var terrain = PosChecker.getTerrainFromPos(x, y);

if (terrain === null || typeof terrain.custom.soundId !== 'number') {
this.playFootstep(unit.getClass());
return;
}

handle = root.createResourceHandle(false, terrain.custom.soundId, 0, 0, 0);

MediaControl.soundPlay(handle);
};

})(); 